/*
\ brief:   实现文件
\ author: 清晨与猫鱼
*/
#include <iostream>     
#include <string>
#include <memory>

using namespace std;

/*
\ brief :  多媒体播放抽象接口类
\ author : 清晨与猫鱼
*/
class MediaPlayer {
public:
    virtual void play(string audioType, string fileName) = 0;
};


/*
\ brief :  高级多媒体播放抽象接口类
\ author : 清晨与猫鱼
*/
class AdvancedMediaPlayer {
public:
    virtual void playVlc(string fileName) = 0;
    virtual void playMp4(string fileName) = 0;
};


/*
\ brief :  Vlc播放
\ author : 清晨与猫鱼
*/
class VlcPlayer 
    : public AdvancedMediaPlayer {
public:
    void playVlc(string fileName) {
        cout << "Playing vlc file. Name: "+ fileName << endl;
    }

    void playMp4(string fileName) {

    }
};


/*
\ brief :  mp4播放
\ author : 清晨与猫鱼
*/
class Mp4Player 
    : public AdvancedMediaPlayer {
public:
    void playVlc(string fileName) {

    }

    void playMp4(string fileName) {
        cout << "Playing mp4 file. Name: "+ fileName << endl;
    }
};


/*
\ brief :  媒体适配器
\ author : 清晨与猫鱼
*/
class MediaAdapter 
    : public MediaPlayer {
public:

/*
\ brief:   根据标识生成VLC播放器还是mp4播放器
\ author: 清晨与猫鱼
*/
    explicit MediaAdapter(string audioType) {
        if (audioType == "vlc") {
            advancedMusicPlayer_.reset(new VlcPlayer);
        }else if (audioType == "mp4") {            
            advancedMusicPlayer_.reset(new Mp4Player);
        }
    }

/*
\ brief:  根据标识播放文件的类型
\ author: 清晨与猫鱼
*/
    void play(string audioType, string fileName) {
        if (audioType == "vlc") {
            advancedMusicPlayer_->playVlc(fileName);
        }else if (audioType == "mp4") {
            advancedMusicPlayer_->playMp4(fileName);
        }
    }
protected:
    unique_ptr<AdvancedMediaPlayer> advancedMusicPlayer_;       // 播放器接口指针
};





/*
\ brief :  音频播放器
\ author : 清晨与猫鱼
*/
class AudioPlayer 
    : public MediaPlayer {
public:
    void play(string audioType, string fileName) {
         //播放 mp3 音乐文件的内置支持
         if (audioType == "mp3") {
             cout << "Playing mp3 file. Name: "+ fileName << endl;
         }
         //mediaAdapter 提供了播放其他文件格式的支持
         else if (audioType == "vlc" || audioType == "mp4") {
             mediaAdapter_.reset(new MediaAdapter(audioType));
             mediaAdapter_->play(audioType, fileName);
         }else {
             cout << "Invalid media. " + audioType + " format not supported" << endl;
         }
    }

protected:
    unique_ptr<MediaAdapter> mediaAdapter_;         // 媒体播放器指针
};


